package cn.cake.reptile.conf;

import java.util.HashMap;
import java.util.Map;

/**
 * @author mengll
 * @date 2019/1/3 14:04
 */
public class Configuration {

    public static final String KEY_COOKIE = "COOKIE";
    public static final String KEY_MAX_EXECUTE_COUNT = "MAX_EXECUTE_COUNT";
    public static final String KEY_CONNECT_TIMEOUT = "CONNECT_TIMEOUT";
    public static final String KEY_READ_TIMEOUT = "READ_TIMEOUT";
    public static final String KEY_EXECUTE_INTERVAL = "EXECUTE_INTERVAL";
    public static final String KEY_MAX_REDIRECT = "MAX_REDIRECT";
    public static final String KEY_DEFAULT_USER_AGENT = "DEFAULT_USER_AGENT";

    private Map<String, Object> data = new HashMap<>();
    private static Configuration defaultConf;

    public Configuration set(String key, Object obj) {
        data.put(key, obj);
        return this;
    }

    public static Configuration getDefaultConf() {
        if (defaultConf == null) {
            synchronized (defaultConf) {
                if (defaultConf == null) {
                    defaultConf = new Configuration();
                    defaultConf.set(KEY_MAX_EXECUTE_COUNT, Config.MAX_EXECUTE_COUNT);
                    defaultConf.set(KEY_CONNECT_TIMEOUT, Config.TIMEOUT_CONNECT);
                    defaultConf.set(KEY_READ_TIMEOUT, Config.TIMEOUT_READ);
                    defaultConf.set(KEY_EXECUTE_INTERVAL, Config.EXECUTE_INTERVAL);
                    defaultConf.set(KEY_MAX_REDIRECT, Config.MAX_REDIRECT);
                    defaultConf.set(KEY_DEFAULT_USER_AGENT, Config.DEFAULT_USER_AGENT);
                }
            }
        }
        return defaultConf;
    }

}
